<div id="user_nomenclatoare_clienti"></div>

<script type="text/javascript">			
Ext.onReady(function(){	
		
		var ds_clienti;
		var cm_clienti;
		var sm_clienti;
		var grid_user_nomenclatoare_clienti;
		var w_user_introducere_client;
		var fp_w_user_introducere_client;
		var w_user_modificare_client;
		var fp_w_user_modificare_client;		

		function clienti_add(){
			if (!w_user_introducere_client) {
						// adaugare client form panel	-----------------------------------------------------
						//-----------------------------------------------------------------------------------	
						fp_w_user_introducere_client = new Ext.FormPanel({
								id: "frm-clienti-add-" + Math.random(),
								labelAlign: 'top',
								bodyStyle: 'padding:5px',
								border: false,
								items		:[{
												layout	:'column',
												border	:false,
												items	:[{
										                	columnWidth	:.5,
															defaultType	:'textfield',								
										                	layout		:'form',
										                	border		:false,
															items		:[new Ext.form.ComboBox({
																				anchor		:'90%',	
																				fieldLabel	:'Statut juridic',
																				name		:'n_tip', 
																				allowBlank	:false,
																				blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>', 
																				editable	:false,	
																				allowBlank	:false,							
																				lazyRender	:true,
																				store		:new Ext.data.Store({
																							     id			:'tip_client_ds',
																								 baseParams	:{saferequest:true,code:'client_type'},
																							     proxy		:new Ext.data.HttpProxy({
																							     				url		:'common/getReference/' + Math.random()
																							 }),
																				 reader		: new Ext.data.JsonReader({
																										        root	:'DS_CLIENT_TYPE',
																										        id		:'value',
																										        fields	:['value', 'option']
																					         })
																			}),
																			hiddenName		:'tip',
																			displayField	:'option',
																			valueField		:'value',									
																			triggerAction	:'all',
																			emptyText		:'[Selectati Statutul]',							
																			listeners		: {
																						'select': function(combo, record, index) {
																							if (this.getRawValue() == 'Persoana fizica') {
																								Ext.getCmp('cnp').reset();
																								Ext.getCmp('cnp').enable();
																								Ext.getCmp('persoana-fizica').expand();															
																								Ext.getCmp('cui').reset();
																								Ext.getCmp('cui').disable();
																								Ext.getCmp('nr_reg').reset();
																								Ext.getCmp('nr_reg').disable();		
																								Ext.getCmp('banca').reset();
																								Ext.getCmp('banca').disable();
																								Ext.getCmp('cont').reset();
																								Ext.getCmp('cont').disable();																																						
																								Ext.getCmp('persoana-juridica').collapse();
																							} else if (this.getRawValue() == 'Persoana juridica'){
																								Ext.getCmp('cui').reset();
																								Ext.getCmp('cui').enable();
																								Ext.getCmp('nr_reg').reset();
																								Ext.getCmp('nr_reg').enable();		
																								Ext.getCmp('banca').reset();
																								Ext.getCmp('banca').enable();
																								Ext.getCmp('cont').reset();
																								Ext.getCmp('cont').enable();																																						
																								Ext.getCmp('persoana-juridica').expand();																
																								Ext.getCmp('cnp').reset();
																								Ext.getCmp('cnp').disable();
																								Ext.getCmp('persoana-fizica').collapse();															
																							}
																						}
																			}
																		}),{
												                    		fieldLabel	:'Nume',
												                    		name		:'nume',
																			anchor		:'90%',
																			allowBlank	:false,
																			blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>'
												                		},{
												                    		fieldLabel	:'Adresa',
												                    		name		:'adresa',
																			anchor		:'90%',
																			allowBlank	:false,
																			blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>'	
												                		},new Ext.form.ComboBox({
																				anchor		:'90%',	
																				fieldLabel	:'Judet',
																				name		:'n_judet', 
																				allowBlank	:false,
																				blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>',
																				editable	:false,								
																				lazyRender	:true,
																				store		:new Ext.data.Store({
																							     id			:'judet_client_ds',
																								 baseParams	:{saferequest:true,code:'county'},
																							     proxy		:new Ext.data.HttpProxy({
																							     				url		:'common/getReference/' + Math.random()
																							 }),
																				 reader		: new Ext.data.JsonReader({
																										        root	:'DS_COUNTY',
																										        id		:'value',
																										        fields	:['value', 'option']
																					         })
																			}),
																			hiddenName		:'judet',
																			displayField	:'option',
																			valueField		:'value',									
																			triggerAction	:'all',
																			emptyText		:'[Selectati Judetul]'
																		}),{
												                    		fieldLabel	:'E-mail',
												                    		name		:'email',
																			anchor		:'90%'															
												                		},new Ext.form.ComboBox({
																				anchor		:'90%',	
																				fieldLabel	:'Platitor TVA?',
																				name		:'n_platitor_tva', 
																				allowBlank	:false, 
																				blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>',
																				editable	:false,								
																				lazyRender	:true,
																				store		:new Ext.data.Store({
																							     id			:'platitor_tva_client_ds',
																								 baseParams	:{saferequest:true,code:'tva_payer'},
																							     proxy		:new Ext.data.HttpProxy({
																							     				url		:'common/getReference/' + Math.random()
																							 }),
																				 reader		: new Ext.data.JsonReader({
																										        root	:'DS_TVA_PAYER',
																										        id		:'value',
																										        fields	:['value', 'option']
																					         })
																			}),
																			hiddenName		:'platitor_tva',
																			displayField	:'option',
																			valueField		:'value',									
																			triggerAction	:'all',
																			emptyText		:'[Selectati]'
																		})
															]			
														},{
										                	columnWidth	:.5,
															defaultType	:'textfield',								
										                	layout		:'form',
										                	border		:false,
															items		:[new Ext.form.FieldSet({
																				id				:'persoana-fizica',
																				anchor			:'90%',
																	            title			:'Persoana fizica',
																	            autoHeight		:true,
																	            collapsible		:true,
																	            defaultType		:'textfield',
																				items			:[{
																									id			:'cnp',
																		                    		fieldLabel	:'CNP',
																		                    		name		:'cnp',
																									anchor		:'90%',
																									disabled	:true,
																									allowBlank	:false,																
																									blankText	:'Pentru statut client "Persoana fizica", acest camp este obligatoriu!'															
																				}]
																		}),new Ext.form.FieldSet({
																				id				:'persoana-juridica',		
																	            title			:'Persoana juridica',
																				anchor			:'90%',
																	            autoHeight		:true,
																	            collapsible		:true,
																	            defaultType		:'textfield',																
																				items			:[{
																									id				:'cui',
																		                    		fieldLabel		:'CUI',
																		                    		name			:'cui',
																									anchor			:'90%',
																									disabled		:true,
																									allowBlank		:false,	
																									blankText		:'Pentru statut client "Persoana juridica", acest camp este obligatoriu!'															
																								},{
																									id				:'nr_reg',
																		                    		fieldLabel		:'Nr. reg. com',
																		                    		name			:'nr_reg',
																									anchor			:'90%',
																									disabled		:true,
																									allowBlank		:false,	
																									blankText		:'Pentru statut client "Persoana juridica", acest camp este obligatoriu!'	
																		                		},{
																									id				:'banca',
																		                    		fieldLabel		:'Banca',
																		                    		name			:'banca',
																									anchor			:'90%',
																									disabled		:true,
																									allowBlank		:false,	
																									blankText		:'Pentru statut client "Persoana juridica", acest camp este obligatoriu!'	
																		                		},{
																									id				:'cont',	
																		                    		fieldLabel		:'Cont',
																		                    		name			:'cont',
																									anchor			:'90%',
																									disabled		:true,
																									allowBlank		:false,	
																									blankText		:'Pentru statut client "Persoana juridica", acest camp este obligatoriu!'	
																		       	}]
																			})
																]															
														}
												]
								}],
						        buttons: [{
											text	:'Save and Close',
						            		tooltip	:'Salvati si Inchideti',
											formBind:true,
											handler : function(){
														if (fp_w_user_introducere_client.getForm().isValid()) {
															fp_w_user_introducere_client.getForm().submit({
																url: "common/insertTable/" + Math.random(),
																params: {
																	saferequest: true,
																	table: 'clienti',
																	cyDep: true
																},
																waitTitle: 'Connecting',
																waitMsg: 'Validating and saving data...',
																success: function(form, action, o){
																	if (action.result.code == 0) {
																		Ext.MessageBox.alert('Atentie:', 'Eroare la adaugare');
																		fp_w_user_introducere_client.getForm().reset();
																	}
																	else 
																		if (action.result.code == 1) {
																			Ext.MessageBox.alert('Mesaj:', 'Adaugare efectuata cu succes!');
																			ds_clienti.reload();
																			fp_w_user_introducere_client.getForm().reset();
																			w_user_introducere_client.hide();
																		}
																},
																failure: function(form, action, o){
																	if (action.failureType == 'server') {
																		Ext.Msg.alert('Warning', 'Cannot save to database!', obj.errors.reason);
																	}
																	else {
																		Ext.Msg.alert('Warning!', 'Authentication server is unreachable!');
																	}
																	fp_w_user_introducere_client.getForm().reset();
																}
															})
														}	
									  			}	
						        		},{
											text: 'Reset',
											tooltip:'Resetati',
											handler: function(){
												fp_w_user_introducere_client.getForm().reset();
												Ext.getCmp('persoana-fizica').expand();		
												Ext.getCmp('persoana-juridica').expand();		
												
											}
										}]														
						});									
						fp_w_user_introducere_client.startMonitoring();	
						
						// end adaugare client form panel	-------------------------------------------------
						//-----------------------------------------------------------------------------------	
															
							w_user_introducere_client = new Ext.Window({
								id				:'w-user-introducere-client' + Math.random(),
								title			:'Adaugare client',
								animateTarget	:'b-add',
								width			:610,
								height			:450,
								plain			:true,
								layout			:'fit',
								modal			:true,
								closeAction		:'hide',
								items			:fp_w_user_introducere_client,
								loadMask		:{msg:'Loading...'},
					            buttons: [{
								    text		:'Cancel',
									tooltip		:'Renuntati',
								    handler		:function(){
										fp_w_user_introducere_client.getForm().reset();
								        w_user_introducere_client.hide();
								    }
								}]
						
							});								

			}else {}
			w_user_introducere_client.show();	
		}	

		function clienti_edit(sID){
			if (!w_user_modificare_client) {
						// editare client form panel	-----------------------------------------------------
						//-----------------------------------------------------------------------------------	
						fp_w_user_modificare_client = new Ext.FormPanel({
								id: "frm-clienti-edit",
								labelAlign: 'top',
								bodyStyle: 'padding:5px',
								border: false,
								items		:[{
												layout	:'column',
												border	:false,
												items	:[{
										                	columnWidth	:.5,
															defaultType	:'textfield',								
										                	layout		:'form',
										                	border		:false,
															items		:[new Ext.form.Hidden({          
																		  	fieldLabel: 'ID',  
																		  	name: 'ID'
																		}),new Ext.form.ComboBox({
																				id			:'id-tip',
																				anchor		:'90%',	
																				fieldLabel	:'Statut juridic',
																				name		:'n_tip', 
																				allowBlank	:false,
																				blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>', 
																				editable	:false,							
																				lazyRender	:true,
																				store		:new Ext.data.Store({
																							     id			:'tip_client_ds',
																								 autoLoad	:true,
																								 baseParams	:{saferequest:true,code:'client_type'},
																							     proxy		:new Ext.data.HttpProxy({
																							     				url		:'common/getReference/' + Math.random()
																							 }),
																				 reader		: new Ext.data.JsonReader({
																										        root	:'DS_CLIENT_TYPE',
																										        id		:'value',
																										        fields	:['value', 'option']
																					         })
																			}),
																			hiddenName		:'tip',
																			displayField	:'option',
																			valueField		:'value',									
																			triggerAction	:'all',
																			emptyText		:'[Selectati Statutul]',							
																			listeners		: {
																						'select': function(combo, record, index) {
																							if (this.getRawValue() == 'Persoana fizica') {
																								Ext.getCmp('cnp').reset();
																								Ext.getCmp('cnp').enable();
																								Ext.getCmp('persoana-fizica').expand();															
																								Ext.getCmp('cui').reset();
																								Ext.getCmp('cui').disable();
																								Ext.getCmp('nr_reg').reset();
																								Ext.getCmp('nr_reg').disable();		
																								Ext.getCmp('banca').reset();
																								Ext.getCmp('banca').disable();
																								Ext.getCmp('cont').reset();
																								Ext.getCmp('cont').disable();																																						
																								Ext.getCmp('persoana-juridica').collapse();
																							} else if (this.getRawValue() == 'Persoana juridica'){
																								Ext.getCmp('cui').reset();
																								Ext.getCmp('cui').enable();
																								Ext.getCmp('nr_reg').reset();
																								Ext.getCmp('nr_reg').enable();		
																								Ext.getCmp('banca').reset();
																								Ext.getCmp('banca').enable();
																								Ext.getCmp('cont').reset();
																								Ext.getCmp('cont').enable();																																						
																								Ext.getCmp('persoana-juridica').expand();																
																								Ext.getCmp('cnp').reset();
																								Ext.getCmp('cnp').disable();
																								Ext.getCmp('persoana-fizica').collapse();															
																							}
																						}
																			}
																		}),{
												                    		fieldLabel	:'Nume',
												                    		name		:'nume',
																			anchor		:'90%',
																			allowBlank	:false,
																			blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>'
												                		},{
												                    		fieldLabel	:'Adresa',
												                    		name		:'adresa',
																			anchor		:'90%',
																			allowBlank	:false,
																			blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>'	
												                		},new Ext.form.ComboBox({
																				anchor		:'90%',	
																				fieldLabel	:'Judet',
																				name		:'n_judet', 
																				allowBlank	:false,
																				blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>',
																				editable	:false,								
																				lazyRender	:true,
																				store		:new Ext.data.Store({
																							     id			:'judet_client_ds',
																								 autoLoad	:true,
																								 baseParams	:{saferequest:true,code:'county'},
																							     proxy		:new Ext.data.HttpProxy({
																							     				url		:'common/getReference/' + Math.random()
																							 }),
																				 reader		: new Ext.data.JsonReader({
																										        root	:'DS_COUNTY',
																										        id		:'value',
																										        fields	:['value', 'option']
																					         })
																			}),
																			hiddenName		:'judet',
																			displayField	:'option',
																			valueField		:'value',									
																			triggerAction	:'all',
																			emptyText		:'[Selectati Judetul]'
																		}),{
												                    		fieldLabel	:'E-mail',
												                    		name		:'email',
																			anchor		:'90%'															
												                		},new Ext.form.ComboBox({
																				anchor		:'90%',	
																				fieldLabel	:'Platitor TVA?',
																				name		:'n_platitor_tva', 
																				allowBlank	:false, 
																				blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>',
																				editable	:false,								
																				lazyRender	:true,
																				store		:new Ext.data.Store({
																							     id			:'platitor_tva_client_ds',
																								 autoLoad	:true,
																								 baseParams	:{saferequest:true,code:'tva_payer'},
																							     proxy		:new Ext.data.HttpProxy({
																							     				url		:'common/getReference/' + Math.random()
																							 }),
																				 reader		: new Ext.data.JsonReader({
																										        root	:'DS_TVA_PAYER',
																										        id		:'value',
																										        fields	:['value', 'option']
																					         })
																			}),
																			hiddenName		:'platitor_tva',
																			displayField	:'option',
																			valueField		:'value',									
																			triggerAction	:'all',
																			emptyText		:'[Selectati]'
																		})
															]			
														},{
										                	columnWidth	:.5,
															defaultType	:'textfield',								
										                	layout		:'form',
										                	border		:false,
															items		:[new Ext.form.FieldSet({
																				id				:'persoana-fizica',
																				anchor			:'90%',
																	            title			:'Persoana fizica',
																	            autoHeight		:true,
																	            collapsible		:true,
																	            defaultType		:'textfield',
																				items			:[{
																									id			:'cnp',
																		                    		fieldLabel	:'CNP',
																		                    		name		:'cnp',
																									anchor		:'90%',
																									disabled	:true,
																									allowBlank	:false,																
																									blankText	:'Pentru statut client "Persoana fizica", acest camp este obligatoriu!'															
																				}]
																		}),new Ext.form.FieldSet({
																				id				:'persoana-juridica',		
																	            title			:'Persoana juridica',
																				anchor			:'90%',
																	            autoHeight		:true,
																	            collapsible		:true,
																	            defaultType		:'textfield',																
																				items			:[{
																									id				:'cui',
																		                    		fieldLabel		:'CUI',
																		                    		name			:'cui',
																									anchor			:'90%',
																									disabled		:true,
																									allowBlank		:false,	
																									blankText		:'Pentru statut client "Persoana juridica", acest camp este obligatoriu!'															
																								},{
																									id				:'nr_reg',
																		                    		fieldLabel		:'Nr. reg. com',
																		                    		name			:'nr_reg',
																									anchor			:'90%',
																									disabled		:true,
																									allowBlank		:false,	
																									blankText		:'Pentru statut client "Persoana juridica", acest camp este obligatoriu!'	
																		                		},{
																									id				:'banca',
																		                    		fieldLabel		:'Banca',
																		                    		name			:'banca',
																									anchor			:'90%',
																									disabled		:true,
																									allowBlank		:false,	
																									blankText		:'Pentru statut client "Persoana juridica", acest camp este obligatoriu!'	
																		                		},{
																									id				:'cont',	
																		                    		fieldLabel		:'Cont',
																		                    		name			:'cont',
																									anchor			:'90%',
																									disabled		:true,
																									allowBlank		:false,	
																									blankText		:'Pentru statut client "Persoana juridica", acest camp este obligatoriu!'	
																		       	}]
																			})
																]															
														}
												]
								}],
						        buttons: [{
											text	:'Save and Close',
						            		tooltip	:'Salvati si Inchideti',
											formBind:true,
											handler : function(){
														if (fp_w_user_modificare_client.getForm().isValid()) {
							           						fp_w_user_modificare_client.getForm().submit({
															  		url: "common/updateTable/" + Math.random(),
																	params:{saferequest:true,table:'clienti'},
															  		waitTitle: 'Connecting..',
															  		waitMsg: 'Validating and saving data...',										
																	success:function(form, action, o) {
																		if(action.result.code === 0){
																			Ext.MessageBox.alert('Atentie:', 'Eroare la actualizare');
																			fp_w_user_modificare_client.getForm().reset(); 	
																		}else if(action.result.code == 1){
																				Ext.MessageBox.alert('Mesaj:', 'Actualizare efectuata cu succes!');
																				ds_clienti.reload();
																				fp_w_user_modificare_client.getForm().reset();
																				w_user_modificare_client.hide();
																		}
																	},										
																	failure: function(form, action, o){
											                            if(action.failureType == 'server'){
											                                Ext.Msg.alert('Warning', 'Cannot save to database!', obj.errors.reason);
											                            }else{
											                                Ext.Msg.alert('Warning!', 'Authentication server is unreachable!');
											                            }
																		fp_w_user_modificare_client.getForm().reset();	
																	}
														  	})
														}	
									  			}	
						        		},{
											text: 'Reset',
											tooltip:'Resetati',
											handler: function(){
												fp_w_user_introducere_client.getForm().reset();
												Ext.getCmp('persoana-fizica').expand();		
												Ext.getCmp('persoana-juridica').expand();		
												
											}
										}]														
						});									
						fp_w_user_modificare_client.startMonitoring();	
						
						// end editare client form panel	-------------------------------------------------
						//-----------------------------------------------------------------------------------	
															
							w_user_modificare_client = new Ext.Window({
								id			:'w-user-modificare-client' + Math.random(),
								title		:'Modificare client',
								width		:610,
								height		:420,
								plain		:true,
								layout		:'fit',
								modal		:true,
								closeAction	:'hide',
								items		:fp_w_user_modificare_client,
								loadMask	:{msg:'Loading...'},
					            buttons: [{
								    text	:'Cancel',
									tooltip	:'Renuntati',
								    handler	:function(){
										fp_w_user_modificare_client.getForm().reset();
								        w_user_modificare_client.hide();
								    }
								}]
						
							});								

			}else {}
			w_user_modificare_client.show();	
			
			fp_w_user_modificare_client.getForm().load({
				url:'common/selectTableWhere/' + Math.random(),                          
				waitMsg:'Loading',
				params:{saferequest:true,table:"clienti",ID:sID},
				success:function(){
					if (Ext.getCmp('id-tip').getRawValue() == 'Persoana fizica') {
						Ext.getCmp('cnp').enable();
						Ext.getCmp('persoana-fizica').expand();															
						Ext.getCmp('cui').disable();
						Ext.getCmp('nr_reg').disable();		
						Ext.getCmp('banca').disable();
						Ext.getCmp('cont').disable();																																						
						Ext.getCmp('persoana-juridica').collapse();
					} else if (Ext.getCmp('id-tip').getRawValue() == 'Persoana juridica'){
						Ext.getCmp('cui').enable();
						Ext.getCmp('nr_reg').enable();		
						Ext.getCmp('banca').enable();
						Ext.getCmp('cont').enable();																																						
						Ext.getCmp('persoana-juridica').expand();																
						Ext.getCmp('cnp').disable();
						Ext.getCmp('persoana-fizica').collapse();															
					}	
				}
			});	
		}			
		
/**
 * grid
 * ************************************************************************
 */			
	    ds_clienti = new Ext.data.Store({
			id			:'table_ds',
	        remoteSort	:true,
			baseParams	:{saferequest:true,table:'clienti',cyDep:true},			
	        proxy: new Ext.data.HttpProxy({
	            url: 'common/getTable/' + Math.random()		
	        }),
	        reader: new Ext.data.JsonReader({
	            root: 'DS_CLIENTI',
	            totalProperty: 'totalCount',
	            id: 'ID',
	            fields: [
	                'tip', 'nume', 'adresa','email', 'activ'
	            ]
	        })
	    });	

		ds_clienti.setDefaultSort('nume', 'desc');
	    ds_clienti.load({params:{start:0, limit:22}});
					
		sm_clienti = new Ext.grid.CheckboxSelectionModel();

	    function rdr_tip(val){
	        if(val == 3){
	            return '<span style="color:green;">Persoana fizica</span>';
	        }else if(val == 4){
	            return '<span style="color:blue;">Persoana juridica</span>';
	        }
	        return val;
	    }
	    function rdr_activ(val){
	        if(val == 1){
	            return '<span style="color:blue;">Activ</span>';
	        }else {
	            return '<span style="color:#e8e8e8;">Inactiv</span>';
	        }
	        return val;
	    }		
	    cm_clienti = new Ext.grid.ColumnModel([sm_clienti,
				{header: "Tip",		dataIndex: 'tip',		renderer: rdr_tip},
				{header: "Nume",	dataIndex: 'nume'},
				{header: "Adresa",	dataIndex: 'adresa'},
				{header: "Email",	dataIndex: 'email'},
				{header: "Activ",	dataIndex: 'activ',	renderer: rdr_activ}
		]);
    	cm_clienti.defaultSortable = true;	
		
	    grid_user_nomenclatoare_clienti = new Ext.grid.GridPanel({
			id:'gridclienti' + Math.random(),
	        renderTo:'user_nomenclatoare_clienti',			
	        height:569,//586,
	        anchor:'100%',						
			frame:false,				
	        title:'<?=$title?>',
	        store: ds_clienti,
	        cm: cm_clienti,
			sm: sm_clienti,
	        loadMask: true,
	        viewConfig: {
	            forceFit:true
	        },
	        bbar: new Ext.PagingToolbar({
				beforePageText:'Pagina&nbsp;',
				afterPageText:'din {0}',
				firstText:'Prima pagina',
				lastText:'Ultima pagina',
				nextText:'Pagina urmatoare',
				prevText:'Pagina precedenta',   
	            pageSize: 22,
	            store: ds_clienti,
	            displayInfo: true,
	            displayMsg: 'Clienti {0} - {1} din {2}',
	            emptyMsg: "No records",
				plugins: new Ext.ux.Andrie.pPageSize({
					  beforeText:'',		
				      afterText: '&nbsp;inreg/pagina',
				      comboCfg: {width: 50}
				      })
			}),plugins: new Ext.ux.grid.Search({
						searchText:'Criterii',
						searchTipText:'Introduceti textul dorit...',
						iconCls:'b_search_cls',
						minChars:2,
						autoFocus:true,
						text:'Cauta dupa camp',
						mode:'remote',
						position:'top'
			}),
	        tbar:[{
				id		:'b-add',
	            text	:'Add ',
	            tooltip	:'Adaugati',
	            iconCls	:'b_add_cls',
				handler	:clienti_add
	        },'-',{
	            text	:'Disable',
	            tooltip	:'Dezactivati',
	            iconCls	:'b_delete_cls',
				handler	: function(){
					if(grid_user_nomenclatoare_clienti.selModel.getCount() >= 1){
					  	Ext.MessageBox.confirm('Confirmation','Dezactivati inregistrarea selectata sau inregistrarile selectate?', function(btn){
							if (btn == 'yes') {
								var selections = grid_user_nomenclatoare_clienti.selModel.getSelections();
								var prez = [];
								for (i = 0; i < grid_user_nomenclatoare_clienti.selModel.getCount(); i++) {
									prez.push(selections[i].json.ID);
								}
								var encoded_array = Ext.encode(prez);
								Ext.Ajax.request({
									waitMsg: 'Va rugam asteptati',
									url: 'common/enableDisableTable/' + Math.random(),
									params: {
										saferequest	:true,
										table		:'clienti',
										ids			:encoded_array,
										action		:'disable'
									},
									success: function(response){
										var result = eval(response.responseText);
										switch (result) {
											case 1:
												ds_clienti.reload();
												break;
											default:
												Ext.MessageBox.alert('Warning', 'Nu puteti dezactiva toate inregistrarile selectate');
												break;
										}
									},
									failure: function(response){
										var result = response.responseText;
										Ext.MessageBox.alert('error', 'could not connect to the database. retry later');
									}
								});
							}							
						}
						);
					} else {
					  	Ext.MessageBox.alert('Warning','Pentru a dezactiva, selectati cel putin o inregistrare!');
					}
					
				}
	        },'-',{
	            text	:'Enable',
	            tooltip	:'Activati',
	            iconCls	:'b_enable_cls',
				handler	: function(){
					if(grid_user_nomenclatoare_clienti.selModel.getCount() >= 1){
					  	Ext.MessageBox.confirm('Confirmation','Activati inregistrarea selectata sau inregistrarile selectate?', function(btn){
							if (btn == 'yes') {
								var selections = grid_user_nomenclatoare_clienti.selModel.getSelections();
								var prez = [];
								for (i = 0; i < grid_user_nomenclatoare_clienti.selModel.getCount(); i++) {
									prez.push(selections[i].json.ID);
								}
								var encoded_array = Ext.encode(prez);
								Ext.Ajax.request({
									waitMsg: 'Va rugam asteptati',
									url: 'common/enableDisableTable/' + Math.random(),
									params: {
										saferequest	:true,
										table		:'clienti',
										ids			:encoded_array,
										action		:'enable'
									},
									success: function(response){
										var result = eval(response.responseText);
										switch (result) {
											case 1:
												ds_clienti.reload();
												break;
											default:
												Ext.MessageBox.alert('Warning', 'Nu puteti activa toate inregistrarile selectate');
												break;
										}
									},
									failure: function(response){
										var result = response.responseText;
										Ext.MessageBox.alert('error', 'could not connect to the database. retry later');
									}
								});
							}							
						}
						);
					} else {
					  	Ext.MessageBox.alert('Warning','Pentru a dezactiva, selectati cel putin o inregistrare!');
					}
					
				}
	        }]
		});							


/**
 * 
 * @param {Object} grid
 * @param {Object} rowIndex
 * @param {Object} e
 */		
		
	grid_user_nomenclatoare_clienti.on('rowdblclick', function(grid, rowIndex, e) {
		if (grid_user_nomenclatoare_clienti.selModel.getCount() == 1) {
			var selection = grid_user_nomenclatoare_clienti.selModel.getSelections();
			var selectedId = selection[0].id;
			//Ext.MessageBox.alert('Warning','ID: ' + selectedId);
			clienti_edit(selectedId);
		} else {
		  	Ext.MessageBox.alert('Warning','Pentru a modifica, selectati doar o inregistrare!');
		}
			
	});
		
});	
</script>